package vo
{
	import flash3.net.ByteArrayPlus;
	
	public class MoneyPoolItem implements ISocket
	{
		public static const MAX_PRIZESPOOL:uint = 8;
		
		public var wKindID:uint;							//类型标识
		public var wServerID:uint;							//房间号码
		public var listPoolItem:Array  = [];				//奖金池描述
		
		public function MoneyPoolItem()
		{
		}
		
		public function read(bap:ByteArrayPlus):void
		{
			clear();
			wKindID = bap.readShort();
			wServerID = bap.readShort();
			var nPoolCount:uint = bap.readShort();
			for(var i:uint = 0; i < nPoolCount; i++)
			{
				var poolItem:ListPoolItem = new ListPoolItem();
				poolItem.read(bap);
				listPoolItem.push(poolItem);
			}
		}
		public function readPrizePool(bap:ByteArrayPlus):void
		{
			wKindID = bap.readShort();
			wServerID = bap.readShort();
			var nPoolCount:uint = bap.readShort();
			for(var i:uint = 0; i < nPoolCount; i++)
			{
				var poolItem:ListPoolItem = listPoolItem[i] ? listPoolItem[i] : new ListPoolItem();
				poolItem.money = bap.readInt();
				poolItem.gold = bap.readInt();
				listPoolItem[i] = poolItem;
			}
		}
		public function write(bap:ByteArrayPlus):void
		{
			
		}
		public function clear():void
		{
			listPoolItem.length = 0;
		}
		
		public function get goldTotal():Number
		{
			var total:uint = 0;
			for(var i:uint = 0; i < listPoolItem.length; i++)
				total += listPoolItem[i].gold;
			return total;
		}
		
		public function getTips(poolIndex:uint, score:int):String
		{
			var retStr:String = null;
			var poolItem:ListPoolItem = listPoolItem[poolIndex];
			if(score != 0 && poolItem && poolItem.tip && poolItem.tip.length != 0)
			{
				retStr = poolItem.tip;
				retStr = retStr.replace("%d", score);
			}
			return retStr;
		}
		
		public function parseJson(obj:Object):void
		{
			wKindID = obj.kindid;
			wServerID = obj.serverid;
			var poolItem:ListPoolItem = new ListPoolItem();
			poolItem.parseJson(obj);
			listPoolItem[obj.orderid-1] = poolItem;
		}
	}
}